package com.vizhuo.base.service.impl;

import java.util.List;

import com.vizhuo.base.dao.BaseMapperI;
import com.vizhuo.base.service.BaseServiceI;

/**
 * <pre>
 * 业务实现类
 * 业务层方法命名需严格遵循以下规则：
 * 1、添加：add开头
 * 2、更新：modify开头
 * 3、删除：remove开头
 * 4、查询：find开头
 * </pre>
 * 
 * @author 刘大年
 * 
 * @param <T>
 *            实体对象类型
 */
public class BaseServiceImpl<T, U, I> implements BaseServiceI<T, U, I> {
    protected BaseMapperI<T, U, I> baseMapper;

    public void setBaseMapper(BaseMapperI<T, U, I> baseMapper) {
        this.baseMapper = baseMapper;
    }

    public BaseMapperI<T, U, I> getBaseMapper() {
        return baseMapper;
    }

    /**
     * 插入数据
     * 
     * @param entity
     * @return
     */
    @Override
    public int addEntity(T entity) {
        return baseMapper.insertEntity(entity);
    }

    /**
     * 修改数据
     * 
     * @param entity
     * @return
     */
    @Override
    public int modifyEntity(T entity) {
        return baseMapper.updateEntity(entity);
    }

    /**
     * 根据id删除数据
     * 
     * @param id
     * @return
     */
    @Override
    public int removeEntityByID(I id) {
        return baseMapper.deleteEntityByID(id);
    }

    /**
     * 根据id集合批量删除数据
     * 
     * @param ids
     * @return
     */
    @Override
    public int removeEntities(I[] ids) {
        return baseMapper.deleteEntities(ids);
    }

    /**
     * 根据id查询一条数据
     * 
     * @param id
     * @return
     */
    @Override
    public T findOneEntity(I id) {
        return baseMapper.selectOneEntity(id);
    }

    /**
     * 条件查询多条数据，无分页
     * 
     * @param entity
     * @return
     */
    @Override
    public List<T> findEntity(U query) {
        return baseMapper.selectEntity(query);
    }

    /**
     * 查询所有对象
     * 
     * @return
     */
    public List<T> findAllEntity() {
        return baseMapper.selectAllEntity();
    }

    /**
     * 修改业务状态
     */
    @Override
    public int modifyStateEntity(T entity) {
        return baseMapper.updateStateEntity(entity);
    }
}
